<?php
/**
 * Nick.php
 *
 * 用户昵称修改表单生成类.
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://momoger.com/license
 *
 * @category	Momoger
 * @package 	Momoger_Form
 * @author 		Guya
 * @version    	1.0
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */

/**
 * 用户昵称修改表单生成类
 *
 * @category	Momoger
 * @package 	Momoger_Form
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */
class Momoger_Form_Nick {

	/**
	 * 创建用户修改昵称 FORM, id 为 nick-form
	 * 昵称长度限制在 4 -20 个字符内.
	 *
	 * @param string $form_action 表单提交地址
	 * @param string $nick 用户现有呢称
	 * @return Zend_Form
	 */
	public function getNickForm($form_action = null, $nick = null) {

		//the input elements attribute: name. There is need validate
		$inputs = array( 'nick' => 'nick');

		//create form object
		$form = new Zend_Form();
		$form->setAction($form_action)
			 ->setMethod('post');
		$form->addAttribs(array('id' => 'nick-form'));

		//create user nick input element
		$userNick = $form->createElement('text',
											$inputs['nick'],
											array(
												'label' => 'New Nick:',
												'class' => 'textInput',
												'id' => 'nick-input',
												'value' => $nick
											));

		//add validator and filter for account input
		$userNick->addValidator('StringLength', FALSE, array(4,20))->addFilter('StripTags');

		$submit = $form->createElement('submit', 'submit', array('label' => 'Rename', 'id'=> 'nick-submit'));
		$form->addElement($userNick)
			 ->addElement($submit);
		return $form;
	}

	/**
	 * 获取自定义错误信息, 修改呢称信息失败可以获取相关的失败信息.
	 *
	 * @param array $errors Zend_Form 错误提示信息
	 * @return array
	 */
	public function getErrorMsgs(array $errors) {

		/** Momoger_Form_Message */
		//require_once 'Message.php';

		return Momoger_Form_Message::getExceptionMsgs($errors, array('nick' => 'Your nick invalid: '));
	}
}